/*
 * @Description: 立即付款btn
 * @Author: buwei.huang
 * @Date: 2019-08-20 15:24:37
 * @Last Modified by: buwei.huang
 * @Last Modified time: 2020-03-12 18:22:56
 */

<script>
import baseBtn from './baseBtn'
import { paymentOrder } from './api'

export default {
  extends: baseBtn,
  props: {
    isDetail: {
      type: Boolean,
      default: null
    },
    orderNo: {
      type: String,
      default: null
    },
    payment: {
      type: String,
      default: null
    },
    tag: {
      type: Number,
      default: null
    },
    pageType: {
      type: String,
      default: null
    },
    outOrderNo: {
      type: String,
      default: null
    }
  },
  data() {
    return {
      isClick: true, // 控制能否再次点击
      btnText: this.isDetail ? '立即付款' : '付款',
      btnClassName: this.isDetail ? 'com_btn_pay_isDetail baseBgColorWithActive' : 'com_btn_pay baseBgColorWithActive'
    }
  },
  computed: {
    route() {
      if (this.pageType === 'TYPE_CUSTOM') {
        return 'TYPE_CUSTOM'
      } else if (this.pageType === 'TYPE_BC') {
        return 'TYPE_BC'
      } else {
        return ''
      }
    }
  },
  mounted() {
    this.$EventBus.$on('afreshState', () => {
      console.log('EventBus~~~~~~~')
      this.isClick = true
    })
  },
  methods: {
    btnEvent() {
      console.log('paybtn---isClick:' + this.isClick)
      if (this.isClick) {
        this.isClick = false
        if (this.payment === 'WXJSPAY') {
          this.$toastMsg('请在嘉定行公众号内完成支付')
          this.isClick = true
          return
        }
        paymentOrder(this.orderNo, this.payment).then(res => {
          try {
            window.doPaymentByType(this.payment, res.PAYMENT_STR, () => {
              this.$AppRouterUtils.open('paymentResult.html?_bbv=false&orderNO=' + this.outOrderNo + '&CR_orderNO=' + this.orderNo + '&CR_payment=' + this.payment + '&paymentStatu=' + 1 + '&PAY_FROM=' + this.route)
            }, () => {
              this.$AppRouterUtils.open('paymentResult.html?_bbv=false&orderNO=' + this.outOrderNo + '&CR_orderNO=' + this.orderNo + '&CR_payment=' + this.payment + '&paymentStatu=' + 0 + '&PAY_FROM=' + this.route)
            })
          } catch (err) {
            console.log('~~~~~~~~try')
            this.isClick = true
          }
        }).catch(err => {
          console.log('~~~~~~~~paymentOrder')
          this.isClick = true
          console.dir(err)
        })
      }
    }
  }
}
</script>
<style>
.com_btn_pay {
  width: 140px;
  height: 48px;
  margin-left: 32px;
  color: #fff;
}
.com_btn_pay_isDetail {
  /* 不知道哪里覆盖了 */
  width: 240px;
  height: 64px;
  color: #fff;
  border-radius: 32px !important;
  font-size: 16px !important; /*no*/
  margin-right: 72px;
}
</style>
